#pragma once
#include <iostream>
#include "protocol.hpp"

class Cal
{
public:
    Cal() {}
    ~Cal() {}
    Responce Service(Request &req)
    {
        Responce ret;
        switch (req.GetOper())
        {
        case '+':
            ret.SetResult(req.Getx() + req.Gety());
            ret.SetCode(0);
            break;
        case '-':
            ret.SetResult(req.Getx() - req.Gety());
            ret.SetCode(0);
            break;
        case '*':
            ret.SetResult(req.Getx() * req.Gety());
            ret.SetCode(0);
            break;
        case '/':
            if (req.Gety() == 0)
                ret.SetCode(1); // 1 -> err : 除0
            else
            {
                ret.SetResult(req.Getx() / req.Gety());
                ret.SetCode(0);
            }
            break;
        case '%':
            if (req.Gety() == 0)
                ret.SetCode(2); // 2 -> err : mod 0
            else
            {
                ret.SetResult(req.Getx() % req.Gety());
                ret.SetCode(0);
            }
            break;
        defalut:
            ret.SetCode(3); // err : 未知
            break;
        }
        return ret;
    }
};